# -*- coding: utf-8 -*-
import os
import transaction
from tg import config, session, request
from tgglobe import model
from sqlalchemy import *

def search_hotel(google_lng, google_lat, range=0.2):
    s = select([model.GoogleAddress,
                model.Post
                ],
               and_(model.GoogleAddress.__table__.c.google_lng.between(google_lng - range, google_lng + range),
                   model.GoogleAddress.__table__.c.google_lat.between(google_lat - range, google_lat + range),
                   model.GoogleAddress.__table__.c.google_address_id == model.Post.__table__.c.post_address_id
                   ),

               )
    ret = model.DBSession.query(model.Hotel).filter(and_(model.GoogleAddress.__table__.c.google_lng.between(google_lng - range, google_lng + range),
                   model.GoogleAddress.__table__.c.google_lat.between(google_lat - range, google_lat + range),
                   model.GoogleAddress.__table__.c.google_address_id == model.Post.__table__.c.post_address_id,
                   model.Post.__table__.c.post_id == model.Hotel.__table__.c.post_id
                   )).all()
    return ret
